﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SPDEV.Search.Utilities;
using Microsoft.SharePoint;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search.Administration;

namespace SPDEV.Search.Utilities.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://test"))
            {
                var serverContext = ServerContext.GetContext(site);
                var searchContext = SearchContext.GetContext(serverContext);

                // ensure all metadata attributes
                var allHiddenProperties = new DisplayHiddenAttributesOfSearchMetadataAdminLayoutsPage(searchContext, serverContext, site);
                var hiddenPropertiesDataTable = allHiddenProperties.CreateDataTable();
                System.Console.WriteLine("Properties : {0}", hiddenPropertiesDataTable.Rows.Count);

                // do a search
                string searchTerm = "test";
                var searchByContent = new SearchContentByPropertyAdminLayoutsPage("Title", searchTerm, site);
                var resultsDataTable = searchByContent.GenerateDataTableOfResults(site);
                System.Console.WriteLine("Results for '{0}' = {1}", searchTerm, resultsDataTable.Rows.Count);

                // get an item
                if (resultsDataTable.Rows.Count > 0)
                {
                    //string itemUrl = resultsDataTable.Rows[0]["URL"] as string;
                    string itemUrl = "http://test/resources/Documents/Forms/AllItems.aspx";
                    var allFieldValues = new DisplayAllKnownPropertiesForContentAdminLayoutsPage(itemUrl);
                    var result = allFieldValues.FindItemPropertiesOrNull();
                }
            }

            System.Console.WriteLine("Done");
            System.Console.ReadKey();

        }
    }
}
